<?php 
define('_VIEW_MODEL_','default');
include("./init.php");
//$result = $db->GetRow('select * from no_admin');
//$userId = getUserId();
$where = "";
$error = "";
$friend = "";
require_once INC.'/pageclass.php';
//$pageObj = new Page(34,10,$smartyObj);
$id = isset($id)?intval($id):"";
$pageSize = 10;
if(isset($act)&&$act=="check"){
	if($st == "noread"){
		$where = "and isread = '0'";
	}
	if($st == "read"){
		$where = "and isread = '1'";
	}
}
if(isset($act)&&$act=="delect"){
	$stat = "";
	if($st == "noread"){
		$stat = "where isread = '0'";
	}
	if($st == "read"){
		$stat = "where isread = '1'";
	}
	$db->GetRow("delete from {$telper}mail $stat");
}
if(isset($act)&&$act=="send"){
	$sid = intval($id);
	$sty = $type;
	$tit = htmlspecialchars($subject);
	$con = htmlspecialchars($message);
	$vla = $msgto;
	$tim = time();
	$sust = true;
	if(!empty($tit)&&!empty($con)&&!empty($vla)){
		$myname = $db->GetRow("select name from {$telper}user where id=$sid");
		if($sty == 'username'){
			$inf = $db->GetRow("select name from {$telper}user where id=$vla");
			if(!empty($inf)){
				$sto = "for=,$vla,forname=$inf[name]";
			}else{
				$sust = false;
				$error = "用户不存在";
			}
		}
		if($sty == 'uid'){
			$inf = $db->GetRow("select id from {$telper}user where name=$vla");
			if(!empty($inf)){
				$sto = "for=,$inf[id],forname=$vla";
			}else{
				$sust = false;
				$error = "用户不存在";
			}
		}
		if($sust){
			$db->Execute("insert {$telper}user set from=$sid,fromname=$myname[name],title=$tit,cont=$con,time=$tim $sto");
		}
	}else{
		$error = "请在所有项里面都输入内容";
	}
}
$rs= $db->Execute("select * from {$telper}mail where `for`= $id and state = '0' $where");
$info = $rs->GetArray();
if(empty($info)){
	$info = "false";
}
//print_R($info);
$num = $db->GetRow("select count(id) from {$telper}mail where `for`= $id and state = '0' order by time desc");
require_once INC.'/pageclass.php';

$rs = $db->Execute("select `title`,`link` from {$telper}friendlink where state = 0 order by rank desc limit 0,6");
$friendinfo = $rs ->GetArray();
foreach($friendinfo as $k=>$v){
	$friend .="<a href='$v[link]'>$v[title]</a>";
	if($k+1 < count($friendinfo)){
		$friend .=".";
	}
}
$nums = !empty($num['count(id)'])?$num['count(id)']:'0';
new Page($nums,$pageSize,$smartyObj);
$tim = time();
header("Content-type:text/vnd.wap.wml;charset=utf-8");
$smartyObj->assign("info",$info);
$smartyObj->assign("uid",$id);
$smartyObj->assign("time",$tim);
$smartyObj->assign("erro",$error);
$smartyObj->assign("friend",$friend);
$smartyObj->display("maillist.tpl");

?>